﻿#region Imports
using System;
#endregion

namespace CommonUtilities.Attributes
{
    /// <summary>
    /// Specifies that the property is filterable
    /// </summary>
    [AttributeUsage(AttributeTargets.Property, Inherited = false, AllowMultiple = false)]
    public sealed class FilterableAttribute : Attribute
    {
        #region Declaration
        /// <summary>
        /// Default value for IsFilterable property
        /// </summary>
        private const bool defaultFilterable = true;

        /// <summary>
        /// Default property name
        /// </summary>
        public static readonly string DefaultPropertyName = "IsFilterable";

        /// <summary>
        /// Specifies the default instance for the <code>CommonUtilities.Attributes.FilterableAttribute</code>
        /// </summary>
        public static readonly FilterableAttribute Default = new FilterableAttribute() { IsFilterable = defaultFilterable };

        /// <summary>
        /// Specifies the default value for the <code>CommonUtilities.Attributes.FilterableAttribute.IsFilterable</code> when property not attributed to
        /// </summary>
        public static readonly bool DefaultValueOnAbsent = !Default.IsFilterable;
        #endregion

        #region Properties
        /// <summary>
        /// Specifies that the property is filterable
        /// </summary>
        public bool IsFilterable { get; private set; }
        #endregion

        #region Constructors
        /// <summary>
        /// Initializes a new default instance of <code>CommonUtilities.Attributes.FilterableAttribute</code>
        /// </summary>
        public FilterableAttribute()
            : base()
        {
            IsFilterable = defaultFilterable;
        }
        #endregion

        #region Methods
        public override bool Equals(object obj)
        {
            return this.IsFilterable == ((FilterableAttribute)obj).IsFilterable;
        }

        /// <summary>
        /// Determines if this attribute is the default instance
        /// </summary>
        /// <returns>TRUE if the attribute is the default instance for this attribute class;
        /// <para>otherwise, FALSE</para></returns>
        public override bool IsDefaultAttribute()
        {
            return this.IsFilterable == Default.IsFilterable;
        }
        #endregion
    }
}
